package com.itheima.service.impl;

import com.itheima.entity.Dept;
import com.itheima.mapper.DeptMapper;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 业务逻辑层，处理具体的业务逻辑
 */
//@Component//程序启动时，会自动创建该类对象，并且交由IOC容器管理
@Service //用来标识当前类属于逻辑处理类，效果也是将该对象交由IOC容器管理
public class DeptServiceImpl implements DeptService {

    //private DeptDao deptDao = new DeptDaoImpl();
    @Autowired
    //从IOC容器中自动寻找bean对象，为该变量赋值
    private DeptMapper deptMapper;
    public List<Dept> list() {
      //1调用mapper的方法，获取列表数据并且返回
      return deptMapper.list();
  }

    @Override
    public void delete(Integer id) {
        deptMapper.delete(id);
    }

    @Override
    public void save(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.save(dept);
    }

    @Override
    public Dept getById(Integer id) {
      return deptMapper.getById(id);

    }

    @Override
    public void update(Dept dept) {
//        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.update(dept);
    }
}
